package com.mmc.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mmc.entity.ContentCategory;
import com.mmc.entity.VO.ContentCategoryListVO;
import com.mmc.mapper.ContentCategoryMapper;
import com.mmc.result.PageResult;
import com.mmc.service.IContentCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 内容分类 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-09-13
 */
@Service
public class ContentCategoryServiceImpl extends ServiceImpl<ContentCategoryMapper, ContentCategory> implements IContentCategoryService {

    @Override
    public PageResult<ContentCategory> selectContentCategoryList(ContentCategoryListVO contentCategory) {
        LambdaQueryWrapper<ContentCategory> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(contentCategory.getName()),ContentCategory::getName,contentCategory.getName());
        Page<ContentCategory> contentCategoryPage = this.baseMapper.selectPage(new Page<>(contentCategory.getPageNum(), contentCategory.getPageSize()), wrapper);

        return new PageResult<>(contentCategoryPage.getTotal(),contentCategoryPage.getRecords());
    }
}
